<?php
class marketing extends ci_controller
{

	function __construct(){
		
		parent::__construct();
		$this->load->library('tank_auth');
		$this->load->library('bamer_lib');
		$this->load->model('modul/marketing_model');
		$this->load->model('user');

		if (!$this->tank_auth->is_logged_in()) redirect('/auth/login/');
		$this->load->helper('bamer_helper');
		$this->lang->load('tank_auth');
		
	}

	function index(){

		//check_permission
		$this->bamer_lib->check_permission_show($this->tank_auth->get_user_id(), 'Marketing');
		$id_m = $this->tank_auth->get_user_id();
		//end
		$id_g = $this->marketing_model->get_id_global($id_m);
		$data['rows_penugasan_marketing'] = $this->marketing_model->list_penugasan_marketing($id_g);
		$data['menu'] = 'halaman kerja';
		$data['head'] = 'layout/head';
        $data['navbar'] = 'layout/navbar';
		$data['content'] = 'modul/marketing/index';
		$this->load->view('layout/inner', $data);
	}


	function edit(){
		//check_permission
		$this->bamer_lib->check_permission_update($this->tank_auth->get_user_id(), 'Marketing');
		//end

		$id = $this->uri->segment(4);

		$data['get_penugasan_marketing_detail'] = $this->marketing_model->isi_penugasan_marketing($id);
		
		$data['menu'] = 'kelola_pegawai';
		$data['head'] = 'layout/head';
        $data['navbar'] = 'layout/navbar';
		$data['content'] = 'modul/marketing/edit';
		$this->load->view('layout/inner', $data);
	
	}

	function update(){
		//check_permission
		$this->bamer_lib->check_permission_update($this->tank_auth->get_user_id(), 'Marketing');
		//end
		$id_m = $this->tank_auth->get_user_id();
		//validation
		$this->form_validation->set_rules('deskripsi_marketing', 'Deskripsi Marketing', 'trim|required|min_length[3]|xss_clean');
		$this->form_validation->set_rules('status_marketing', 'Status Marketing', 'trim|required|min_length[5]|xss_clean');
		
		if ($this->form_validation->run() == FALSE)
		{
			
		//end
				$id = $this->input->post('id_penugasan_marketing');
				$data['get_penugasan_marketing_detail'] = $this->marketing_model->isi_penugasan_marketing($id);
		
				$data['menu'] = 'kelola_pegawai';
				$data['head'] = 'layout/head';
		        $data['navbar'] = 'layout/navbar';
				$data['content'] = 'modul/marketing/edit';
				$this->load->view('layout/inner', $data);
		}
		else
		{
				$date = get_date_time();

				$data_marketing = array(
				'deskripsi_hasil_marketing' => $this->input->post('deskripsi_marketing'),
				'waktu_marketing' => $date,
				);

			$where_penugasan_marketing = array('id_penugasan_marketing' => $this->input->post('id_penugasan_marketing'));
			$this->user->update('penugasan_marketing',$where_penugasan_marketing, $data_marketing);

				$data_status_marketing = array(
				'status_marketing_perusahaan' => $this->input->post('status_marketing'),
				);
			$where_status_marketing = array('id_perusahaan' => $this->input->post('id_perusahaan'));
			$this->user->update('perusahaan',$where_status_marketing, $data_status_marketing);
			redirect('modul/marketing/index');
		}

	}
}
?>